<?php
require_once("../class/connect.php");
require_once("../class/db_sql.php");
require_once("../class/q_functions.php");
require_once("../class/qinfofun.php");
require_once("../class/user.php");
require_once("../data/dbcache/class.php");
require_once("../data/dbcache/MemberLevel.php");
$link=db_connect();
$empire=new mysqlquery();
//?mid=10&enews=MAddInfo&classid=65
$jat_id=$_GET['a']?$_GET['a']:$_GET['e'];
$_id=$_REQUEST['id'];
$mode_id=$_REQUEST['m'];
$addConfigArr=array("65"=>array(
							"add"=>"MAddInfo",
							"edit"=>"MEditInfo",
							"classid"=>65,
							"mid"=>10,
							"js"=>	$public_r[newsurl]."",
							"css"=>	$public_r[newsurl]."",
							"my_link"=>array('<a class="tips active"  href="#">添加活动</a>','<a class="tips "  href="">我创建的活动</a>'),
							"ta_link"=>array("TA创建的活动"),
							),
					"69"=>array(
							"enews"=>"MAddInfo",
							"add"=>"MAddInfo",
							"edit"=>"MEditInfo",
							"classid"=>69,
							"mid"=>11,
							"js"=>$public_r[newsurl].'skin/default/js/city_select.js',//http://192.168.3.59:8181/cms/em//skin/default/js/city_select.js
							"css"=>"",
							"my_link"=>array('<a class="tips active"  href="./?e='.$jat_id.'&id='.$_id.'">我创建的部落</a>','<a class="tips "  href="../i/?e='.$jat_id.'&id='.$_id.'&m=eh">编辑部落图标</a>'),
							"ta_link"=>array("TA创建的活动"),
							"skin"=>"e/template/DoInfo/jat_edit_tribe.php",
							));


$mode=array(
				'eh'=>array(
							'sql'=>'SELECT * FROM phome_ecms_tribe WHERE id="'.$_id.'"',							
							'skin'=>'e/template/DoInfo/jat_edit_tribe_head.php',
							'numsql'=>'SELECT COUNT(T.id) as total FROM 
												phome_ecms_tribe T 
											LEFT JOIN
												phome_jat_jointribe C ON C.tid=T.id
											WHERE C.uid="'.$user[userid].'"',
							'my_link'=>'',
							)
				//''=>
			);

$configApp=$editConfigArr[$mid];

	$configApp=$addConfigArr[$jat_id];
	if(!is_array($configApp)){ echo "error!"; exit();}
	if($_GET['a']){
		$appAction	= $configApp[add];
	}elseif($_GET['e']){
		$appAction= $configApp[edit];
	}



if($mode_id && is_array($mode[$mode_id])){
	$configApp=array_merge($configApp,$mode[$mode_id]);
}
if($configApp['sql']){
	$r=$empire->fetch1($configApp['sql']);
	print_r($r);
}else{
	$app_id			= $_GET['id'];
	$appClassId		=  $configApp['classid'];
	$_GET[enews]	= $appAction;
	$_GET[classid]	= $configApp[classid];
	$_GET[mid]		= $configApp[mid];
	//print_r($_GET);
	$page_load_js=$configApp[js];

	if($public_r['addnews_ok'])//关闭投稿
	{
		printerror("NotOpenCQInfo","",1);
	}
	//mid=10&enews=MAddInfo&classid=65
	$classid=(int)$_GET['classid'];
	$mid=$class_r[$classid]['modid'];
	if(empty($classid)||empty($mid))
	{
		printerror("EmptyQinfoCid","",1);
	}
	$enews=$_GET['enews'];
	if(empty($enews))
	{
		$enews="MAddInfo";
	}
	$r=array();
	$muserid=(int)getcvar('mluserid');
	$musername=RepPostVar(getcvar('mlusername'));
	$mrnd=RepPostVar(getcvar('mlrnd'));
	$newstime=time();
	$r[newstime]=date("Y-m-d H:i:s");
	$todaytime=$r[newstime];
	$showkey="";
	$r['newstext']="";
	//取得登陆会员资料
	if($muserid)
	{
		$memberinfor=$empire->fetch1("select u.*,ui.* from ".$user_tablename." u LEFT JOIN {$dbtbpre}enewsmemberadd ui ON u.{$user_userid}=ui.userid where u.{$user_userid}='$muserid' limit 1");
	}
	//增加
	if($enews=="MAddInfo")
	{
		$cr=DoQCheckAddLevel($classid,$muserid,$musername,$mrnd,0,1);
		$mr=$empire->fetch1("select qenter,qmname from {$dbtbpre}enewsmod where mid='$cr[modid]'");
		if(empty($mr['qenter']))
		{
			printerror("NotOpenCQInfo","history.go(-1)",1);
		}
		$word="提交信息";
		$ecmsfirstpost=1;
		$rechangeclass="&nbsp;[<a href='ChangeClass.php?mid=".$mid."'>重新选择</a>]";
		//验证码
		if($cr['qaddshowkey'])
		{
			$showkey="<tr bgcolor=\"#FFFFFF\">
		  <td width=\"11%\" height=\"25\">验证码</td>
		  <td height=\"25\"><input name=\"key\" type=\"text\" size=\"6\">
			<img src=\"../ShowKey/?v=info\"></td></tr>";
		}
		//图片
		$imgwidth=0;
		$imgheight=0;
		//文件验证码
		$filepass=time();
	}
	else
	{
		$word="修改信息";
		$ecmsfirstpost=0;
		$id=(int)$_GET['id'];
		if(empty($id))
		{
			printerror("EmptyQinfoCid","",1);
		}
		$cr=DoQCheckAddLevel($classid,$muserid,$musername,$mrnd,1,0);
		$mr=$empire->fetch1("select qenter,qmname from {$dbtbpre}enewsmod where mid='$cr[modid]'");
		if(empty($mr['qenter']))
		{
			printerror("NotOpenCQInfo","history.go(-1)",1);
		}
		$r=CheckQdoinfo($classid,$id,$muserid,$cr['tbname'],$cr['adminqinfo'],1);
		//检测时间
		if($public_r['qeditinfotime'])
		{
			if(time()-$r['truetime']>$public_r['qeditinfotime']*60)
			{
				printerror("QEditInfoOutTime","history.go(-1)",1);
			}
		}
		$newstime=$r['newstime'];
		$r['newstime']=date("Y-m-d H:i:s",$r['newstime']);
		//图片
		$imgwidth=170;
		$imgheight=120;
		//文件验证码
		$filepass=$id;
	}
	$tbname=$cr['tbname'];
	esetcookie("qeditinfo","dgcms");
	//专题
	$ztwhere=ReturnClass($class_r[$classid][featherclass]);
	$z_sql=$empire->query("select ztname,ztid,tbname from {$dbtbpre}enewszt where usezt=0 and (classid=0 or classid='$classid' or (".$ztwhere.")) order by ztid");
	$j=0;
	$br='';
	while($z_r=$empire->fetch($z_sql))
	{
		$j++;
		if($j%8==0)
		{
			$br='<br>';
		}
		else
		{
			$br='';
		}
		$select='';
		if(strstr($r[ztid],'|'.$z_r[ztid].'|'))
		{
			$select=" checked";
		}
		$zts.="<input type=checkbox name=ztid[] value='".$z_r[ztid]."'".$select.">".$z_r[ztname]."&nbsp;".$br;
	}
	//标题分类
	$tts='';
	$ttsql=$empire->query("select typeid,tname from {$dbtbpre}enewsinfotype where mid='$cr[modid]' order by myorder");
	while($ttr=$empire->fetch($ttsql))
	{
		$select='';
		if($ttr[typeid]==$r[ttid])
		{
			$select=' selected';
		}
		$tts.="<option value='$ttr[typeid]'".$select.">$ttr[tname]</option>";
	}
	//栏目
	$classurl=sys_ReturnBqClassname($cr,9);
	$postclass="<a href='".$classurl."' target='_blank'>".$class_r[$classid]['classname']."</a>".$rechangeclass;
	if($cr['bclassid'])
	{
		$bcr['classid']=$cr['bclassid'];
		$bclassurl=sys_ReturnBqClassname($bcr,9);
		$postclass="<a href='".$bclassurl."' target=_blank>".$class_r[$cr['bclassid']]['classname']."</a>&nbsp;>&nbsp;".$postclass;
	}
	//html编辑器
	if($emod_r[$mid]['editorf']&&$emod_r[$mid]['editorf']!=',')
	{
		include('../data/ecmseditor/infoeditor/fckeditor.php');
	}
	if(empty($musername))
	{
		$musername="游客";
	}
	if($configApp['js']){
		$page_load_js=$configApp['js'];
	}
	$modfile="../data/html/q".$cr['modid'].".php";
	//导入模板
	if($_GET["ajax_form_only"]==1){	
		  @include($modfile);
		 // exit();
	}
}
if($_GET["ajax_form_only"]!=1){
	if($appAction['skin']){
		require(ECMS_PATH.$configApp['skin']);
				
			//'e/template/DoInfo/jat_edit_tribe.php');
	}else{
		require(ECMS_PATH.'e/template/DoInfo/jat_edit_add.php');
	}
}
db_close();
$empire=null;
?>